// pages/help/help.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       var openid = wx.getStorageSync('useronlyData').openid;
       this.setData({
         openId :　openid
       })
       var that = this;
       wx.request({
         url: 'http://localhost:8080/findByOpenId?openId=' + that.data.openId,
         method : 'GET',
         data:{},
         success:function(res){
           var user = res.data.user;
           if (user == null){
             that.setData({
               userId: 9999
             })
           }else{
             var userId = res.data.user.id;
           that.setData({
             userId: userId
           })
           }
         }
       })
  },
  radioChange:function(e){
    var that = this;
    var value = e.detail.value
    that.setData({
      sex: value
    })
  },
  radioChange2: function (e) {
    var that = this;
    var value = e.detail.value
    that.setData({
      change_type: value
    })
  },
  
  
  formSubmit: function (e) {
    var user = e.detail.value

    var that = this;
    wx.request({
      url: 'http://localhost:8080/help_other/add',
      method: 'GET',
      data: {
        userId: that.data.userId,
        name: user.inputName,
        sex: that.data.sex,
        Hometown: user.inputHomeTown,
        IDCard:user.inputIDCard,
        Phone: user.inputPhone,
        address: user.inputAddress,
        reason: user.inputReason,
        amount: user.inputAmount,
        type:that.data.change_type

      },

      success: function (res) {
        var isSuccess = res.data.isSuccess;
        if (isSuccess == true) {
        
          wx.showToast({
            title: '申请成功',
            icon: 'success',
            duration: 2000
          })

        } else if (isSuccess == false){
          
          var toastText = '获取数据失败' + res.data.errMsg;
          wx.showToast({
            title: '申请失败,请重新申请',
            icon: 'none',
            duration: 2000
          })
        }else{
          wx.showToast({
            title: isSuccess,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})